package com.niit.zerotestpdfreader;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.niit.zerotestpdfreader.entity.Recent;

import java.util.ArrayList;
import java.util.List;

public class RecentReading extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recent_reading);

//        Intent intent = getIntent();
//        List<Recent> recents = (List)intent.getSerializableExtra("list");

        List<Recent> recents = (List<Recent>) getIntent().getSerializableExtra("list");

        String[] newColume = new String[recents.size()];
        for (int i=0; i<recents.size(); i++) {
            newColume[i] = recents.get(i).getRecentPath();
        }

        ArrayAdapter<String> adapter=new ArrayAdapter<String>(RecentReading.this,android.R.layout.simple_list_item_1, newColume);
        ListView listview=(ListView)findViewById(R.id.list_view);
        listview.setAdapter(adapter);

        Intent intent = new Intent(this, PdfPage.class);

        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                view.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        String objectItem = adapter.getItem(i);
//                        Toast.makeText(RecentReading.this, objectItem, Toast.LENGTH_LONG).show();
                        intent.putExtra("path", objectItem);
                        startActivity(intent);
                    }
                });
            }
        });

    }
}